package com.play.ballen.mall.ui.im


import androidx.fragment.app.Fragment
import com.play.ballen.R
import com.play.ballen.databinding.FragmentImBinding
import com.play.ballen.im.fragment.ConversationListFragment
import com.play.ballen.mall.ui.MallSaleFragment
import com.yuven.appframework.adapter.BaseViewPagerAdapter
import com.yuven.baselib.component.BaseMVVMFragment
import com.yuven.baselib.component.viewmodel.BaseViewModel.EmptyVM
import com.yuven.baselib.utils.ViewUtils

class IMFragment : BaseMVVMFragment<EmptyVM, FragmentImBinding>() {

    private var isLoadData = false

    private val fragmentConvo by lazy {
        ConversationListFragment()
    }
    private val fragmentUser by lazy {
        MallSaleFragment.newInstance(TYPE_MALL_USER)
    }

    private val fragmentList by lazy {
        arrayListOf<Fragment>(fragmentConvo, fragmentUser)
    }

    private lateinit var adapter: BaseViewPagerAdapter

    private val titles = arrayListOf("消息","通讯录")

    private var selectLevelId = ""


    companion object {
        val TAG: String = IMFragment::class.java.simpleName

        const val TYPE_MALL_OFFICIAL = "0"
        const val TYPE_MALL_USER = "1"

        fun newInstance(): IMFragment {
            return IMFragment()
        }
    }

    override fun initIntent() {}

    override fun layoutId(): Int {
        return R.layout.fragment_im
    }

    override fun viewModelClass(): Class<EmptyVM> {
        return EmptyVM::class.java
    }

    override fun initView() {
        dataBinding.fakeStatusBar.layoutParams.height = ViewUtils.getStatusHeight()

    }

    override fun initData() {

    }

    override fun onResume() {
        super.onResume()
        if (!isLoadData) {
            adapter = BaseViewPagerAdapter(childFragmentManager, fragmentList, titles)
            dataBinding.viewPager.adapter = adapter
            dataBinding.viewPager.offscreenPageLimit = fragmentList.size
            dataBinding.tabLayout.setViewPager(dataBinding.viewPager)
            isLoadData = true
        }
    }

}